package com.zking.controller.jch;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zking.entity.Goods;
import com.zking.service.jch.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/GoodsAudit")
public class GoogsAuditController {
    @Autowired
    private GoodsService goodService;




    @RequestMapping(value = "/selectGoodsStatusAll")
    @ResponseBody
    public PageInfo  getGoodsStatusAll(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum,
                                             @RequestParam(defaultValue = "5") int pageSize,String goodsname){

        try {
            if (goodsname !=null && !goodsname.isEmpty() ){
                PageHelper.startPage(pageNum, pageSize);
                PageInfo pageInfo = new PageInfo(goodService.GoodLike(goodsname));
                System.out.println(pageInfo.getList());
                return pageInfo;
            }

            PageHelper.startPage(pageNum, pageSize);
            PageInfo pageInfo = new PageInfo(goodService.queryGoodsAuditAll());
            System.out.println(pageInfo.getList());
            return pageInfo;

        } catch (Exception e) {

            return null;
        }
    }



//    @RequestMapping("/GoodLike")
//    @ResponseBody
//    public List<Goods> getGoodLike(String goodsname) {
//        List<Goods> goods = goodService.GoodLike(goodsname);
//        System.out.println(goods);
//        return goods;
//    }

    @RequestMapping(value = "/del" , method = RequestMethod.GET)
    public String delGoods(String id) {
        boolean b = goodService.delGoods(id);
        System.out.println(b);
        return"jch/goods";
    }

    @RequestMapping(value = "/success" , method = RequestMethod.GET)
    public String Approved(String id) {
        boolean b = goodService.Approved(id);
        System.out.println(b);
        return"jch/goods";
    }
    @RequestMapping(value = "/defeat" , method = RequestMethod.GET)
    public String reject(String id) {
        boolean b = goodService.reject(id);
        System.out.println(b);
        return"jch/goods";
    }
}
